from flask import Flask, request
from flask import Blueprint

import json

from bilstm_model import bilstm_model_01 as bilstm_01


bilstm_routes = Blueprint('bilstm_routes', __name__)


@bilstm_routes.route('/bilstm_01/v1', methods=['post'])
def bilstm_model_01():
    """blistm 模型 V4"""
    if not request.data:  # 检测是否有数据
        return ''

    params = request.data.decode('utf-8', errors='ignore')

    # 获取到POST过来的数据，因为我这里传过来的数据需要转换一下编码。

    input_params = json.loads(params)

    probability_label_1 = bilstm_01.predict_probability(input_params, bilstm_01.model, bilstm_01.tokenizer)

    return str(probability_label_1)
